package com.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gmall.common.result.Result;
import com.gmall.model.product.BaseTrademark;
import com.gmall.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark/")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;
    ///admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result<Page<BaseTrademark>> findPage(@PathVariable Integer page,
                                                @PathVariable Integer limit){

       /* try {
            int i = 10 / 0;
        }catch (RuntimeException e){
            throw new GmallGlobalException("自定义异常",500);
        }*/
        return baseTrademarkService.findPage(page,limit);
    }

    @PostMapping("save")
    public Result<String> saveTrademark(@RequestBody BaseTrademark baseTrademark){
        return baseTrademarkService.save(baseTrademark);
    }

    @PutMapping("update")
    public Result<String> update(@RequestBody BaseTrademark baseTrademark){
        return baseTrademarkService.update(baseTrademark);
    }

    @DeleteMapping("remove/{id}")
    public Result<String> remove(@PathVariable Long id){
        return baseTrademarkService.remove(id);
    }


    @GetMapping("get/{id}")
    public Result<BaseTrademark> getById(@PathVariable Long id) {
        return baseTrademarkService.getById(id);
    }
}
